package jp.gr.java_conf.ionexux.feztimer;

import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.media.AudioManager;
import android.os.Bundle;
import android.util.Log;

public class MainActivity extends Activity {

	private String TAG = "MainActivity";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Log.d(TAG, "onCreate");
		setContentView(R.layout.main);
		setVolumeControlStream(AudioManager.STREAM_MUSIC);

		// setup Action Bar for tabs
		final ActionBar actionBar = getActionBar();
		actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

		// instantiate fragment for the tab
		PowerFragment powerFragment = new PowerFragment();
		// add a new tab and set its title text and tab listener
		actionBar.addTab(actionBar.newTab().setText("power")
				.setTabListener(new MyTabListener(powerFragment)));

		CrystalFragment crystalFragment = new CrystalFragment();
		// add a new tab and set its title text and tab listener
		actionBar.addTab(actionBar.newTab().setText("crystal")
				.setTabListener(new MyTabListener(crystalFragment)));

		BookFragment bookFragment = new BookFragment();
		// add a new tab and set its title text and tab listener
		actionBar.addTab(actionBar.newTab().setText("book")
				.setTabListener(new MyTabListener(bookFragment)));
	}

	@Override
	protected void onResume() {
		super.onResume();
		Log.d(TAG, "onResume");
	}

}

class MyTabListener implements ActionBar.TabListener {
	private Fragment mFragment;

	// Called to create an instance of the listener when adding a new tab
	public MyTabListener(Fragment fragment) {
		mFragment = fragment;
	}

	public void onTabSelected(Tab tab, FragmentTransaction ft) {
		ft.replace(R.id.content, mFragment);
	}

	public void onTabUnselected(Tab tab, FragmentTransaction ft) {
		ft.remove(mFragment);

	}

	public void onTabReselected(Tab tab, FragmentTransaction ft) {

	}

}